﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EntityComponentSystem.Framework;
using System.Threading;

namespace ECS.Demos.Tetris
{
    public partial class Form1 : Form
    {
        //private GameEngine ge = null;
        private Thread thread = null;
        public Form1()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.Opaque, true);
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.FixedHeight, true);
            this.SetStyle(ControlStyles.FixedWidth, true);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);


            //using (var g = Graphics.FromImage(bg))
            //    g.FillRectangle(Brushes.Black, new Rectangle(0, 0, 500, 500));

            //cs = new RicochetSystem();

            //ge = new GameEngine();
            //ge.Start();

            //var ps = new PositionableSystem(ge);
            


            //var nextid = 0;
            //for (var i = 0; i < 10000; i++)
            //    ge.RicochetSystem.AddEntity(new Entity(ge));

            //Application.Idle += new EventHandler(Application_Idle);

            thread = new Thread(new ThreadStart(Loop));
            thread.Start();
        }

        void Loop()
        {
        }
        //private bool frame = false;
        void Application_Idle(object sender, EventArgs e)
        {
            //cs.Update(100);
            //frame = !frame;
            //this.Invalidate();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);


            //using (var g = Graphics.FromImage(bg))
            //{
            //    foreach (var com in coms)
            //        g.FillRectangle(frame ? Brushes.White : Brushes.Black, com.Position.X, com.Position.Y, 1, 1);
            //}
            //if (ge.RenderSystem.WaitForFormUpdate)
            //{
            //    e.Graphics.DrawImageUnscaled(ge.RenderSystem.Bitmap, 0, 0, 1000, 1000);
            //    ge.RenderSystem.WaitForFormUpdate = false;
            //}
        }
    }
}
